package beautiful.butterfly.drds.data_exchange.statistics.jvm_info;

import beautiful.butterfly.drds.data_exchange.statistics.JvmInfo;


public class CpuStatus
{
    // 百分比的值 比如30.0 表示30.0%
    public float cpuUsage = -1;
    public float minCpuUsage = -1;
    public float maxCpuUsage = -1;
    //
    public float averageCpuUsage = -1;
    private JvmInfo jvmInfo;

    public CpuStatus(JvmInfo jvmInfo)
    {
        this.jvmInfo = jvmInfo;
    }

    public void setCpuUsage(float cpuUsage)
    {
        this.cpuUsage = cpuUsage;
        if (maxCpuUsage < cpuUsage)
        {
            maxCpuUsage = cpuUsage;
        }

        if (minCpuUsage == -1 || minCpuUsage > cpuUsage)
        {
            minCpuUsage = cpuUsage;
        }
    }

    public String getDeltaString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append("\n\t [delta cpu info] => \n");
        sb.append("\t\t");
        sb.append(String.format("%-30s | %-30s | %-30s | %-30s \n", "cpuUsage", "averageCpuUsage", "minCpuUsage", "maxCpuUsage"));
        sb.append("\t\t");
        sb.append(String.format("%-30s | %-30s | %-30s | %-30s \n",
                String.format("%,.2f%%", jvmInfo.cpuStatus.cpuUsage),
                String.format("%,.2f%%", jvmInfo.cpuStatus.averageCpuUsage),
                String.format("%,.2f%%\n", jvmInfo.cpuStatus.minCpuUsage),
                String.format("%,.2f%%", jvmInfo.cpuStatus.maxCpuUsage)
        ));

        return sb.toString();
    }

    public String getTotalString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append("\n\t [total cpu info] => \n");
        sb.append("\t\t");
        sb.append(String.format("%-30s | %-30s | %-30s \n", "averageCpuUsage", "minCpuUsage", "maxCpuUsage"));
        sb.append("\t\t");
        sb.append(String.format("%-30s | %-30s | %-30s \n",
                String.format("%,.2f%%", jvmInfo.cpuStatus.averageCpuUsage),//
                String.format("%,.2f%%\n", jvmInfo.cpuStatus.minCpuUsage),//
                String.format("%,.2f%%", jvmInfo.cpuStatus.maxCpuUsage)));//

        return sb.toString();
    }

}
